<?php
class AdvertisementMessage extends Zend_Db_Table_Abstract {
	const ADVERTISEMENT = "advertisement_id";
	const MESSAGE = "message_id";
	
	protected $_name = "advertisement_message";
	
	protected $_referenceMap = array (
	'Advertisement' => array (
		'columns' => 'advertisement_id', 
		'refTableClass' => 'Advertisement', 
		'refColumns' => 'id' 
	),
	'Message' => array (
		'columns' => 'message_id',
		'refTableClass' => 'Message',
		'refColumns' => 'id'
	)
	);
	
	public function addEntry($data) {
		$obj = $this->findByUnique($data["advertisement_id"], $data["message_id"]);
		if (!isset($obj)) {
			$this->insert($data);
		}
	}
	
	/**
	 * Find by unique constraint.
	 * 
	 * @param $advertisement_id
	 * @param $message_id
	 */
	public function findByUnique($advertisement_id, $message_id) {
		$where = $this->select()->where("advertisement_id=?", $advertisement_id)->where("message_id=?", $message_id);
		return $this->fetchRow($where);
	}
}
?>